package leetcode.leetcode225;

import java.util.LinkedList;

/**
 * @author czt
 * @version 1.0
 * @since 2024/12/20
 *
 * 队列实现栈
 */
public class Leetcode225 {

    LinkedList<Integer> queue = new LinkedList<>();

    int size = 0;

    public void push(int x) {
        queue.offer(x);
        for (int i = 0; i < size; i++) {
            queue.offer(queue.poll());
        }
        size++;
    }

    public int pop() {
        if (queue.isEmpty()) {
            return -1;
        }
        size--;
        return queue.poll();
    }

    public int top() {
        if (queue.isEmpty()) {
            return -1;
        }
        return queue.peek();
    }

    public boolean empty() {
        return queue.isEmpty();
    }
}
